package router

import (
	jwt "gitee.com/sansaniot/ssiot-core/httpmvc/jwtauth"
	"github.com/gin-gonic/gin"

	"ssdevice/internal/device/apis"
)

func init() {
	RouterCheckRole = append(RouterCheckRole, registerDeviceRouter)
}

func registerDeviceRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
	api := apis.Device{}
	// 设备
	r := v1.Group("/api/device").Use(authMiddleware.MiddlewareFuncWithOutValidate())
	{
		r.GET("/find", api.FindList)
		r.GET("/get", api.FindOne)
		r.POST("/add", api.AddDevice)
		r.POST("/modify", api.EditDevice)
		r.Any("/initName4Product", api.InitName4Product)
		r.POST("/remove", api.DeleteDevice)
		r.POST("/changeGroup", api.ChangeGroup)
		r.POST("/save/product", api.DeviceSaveProduct)
		r.POST("/config/save", api.UpsertEntireConfig)
		r.POST("/channel/diagnose", api.ChannelDiagnose)

		// 公共
		r.GET("/find/all", api.FindAllList)
		r.GET("/stat/count", api.FindStatCount)

		// 下发配置与获取
		r.POST("/config/set", api.SetDeviceConfig)
		r.POST("/config/get", api.GetDeviceConfig)
		// 下发变量
		r.POST("/sensor/set", api.SetDeviceSensor)
		// 下发变量
		r.POST("/sensor/get", api.GetDeviceSensor)
		// 下发控制
		r.POST("/func/set", api.SendDeviceFunc)
	}
	// 设备历史数据
	r4 := v1.Group("/api/device/historydata").Use(authMiddleware.MiddlewareFuncWithOutValidate())
	{
		r4.GET("/find", api.FindDeviceHistoryData)
		r4.GET("/get", api.GetDeviceHistoryData)
		r4.POST("/report", api.GetDeviceHistoryReport)
	}
	// 设备历史数据
	r3 := v1.Group("/api/device/historysystem").Use(authMiddleware.MiddlewareFuncWithOutValidate())
	{
		r3.GET("/find", api.FindDeviceHistorySystem)
		r3.GET("/get", api.GetDeviceHistorySystem)
	}

	// 报表表单
	api1 := apis.ReportForms{}
	r5 := v1.Group("/api/device/report/form").Use(authMiddleware.MiddlewareFuncWithOutValidate())
	{
		r5.GET("/find", api1.FindReportFormList)
		r5.POST("/add", api1.AddReportForms)
		r5.POST("/del", api1.DeleteReportForms)
	}
}

func setSensor() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.Set("sensor", "sensor")
	}
}
